refactor: relocate misplaced functions to appropriate modules#12673
Closed
refactor: relocate misplaced functions to appropriate modules#12673
Conversation
Move ensureGitAttributes() and stageGitAttributesIfChanged() from git.go to compile_post_processing.go. These functions are specific to workflow compilation post-processing, not general git operations. - Moved ensureGitAttributes() to compile_post_processing.go - Moved stageGitAttributesIfChanged() to compile_post_processing.go - Updated logging to use compilePostProcessingLog instead of gitLog - Added os/exec and strings imports to compile_post_processing.go - All tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move confirmPushOperation() from git.go to interactive.go. This function is user interaction logic, not a core git operation. - Moved confirmPushOperation() to interactive.go - Updated logging to use interactiveLog instead of gitLog - Removed unused huh import from git.go - All tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move validateCompileConfig() from compile_validation.go to compile_config.go. This function validates CLI configuration flags, not workflow content, so it belongs with the CompileConfig struct definition. - Moved validateCompileConfig() to compile_config.go - Updated logging to use compileConfigLog instead of compileValidationLog - Added fmt and path/filepath imports to compile_config.go - All tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move validateActionYml() from actions_build_command.go to validators.go. This is a reusable validation function that should be centralized with other validators for better discoverability. - Moved validateActionYml() to validators.go - Added fmt, os, and path/filepath imports to validators.go - Simplified function documentation - All tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Apply go fmt formatting to files after refactoring. Removes trailing blank lines and extra whitespace per project standards. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Remove orphaned function comment for confirmPushOperation that was moved to interactive.go. This comment was inadvertently left behind during refactoring. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor code organization based on semantic analysis
refactor: relocate misplaced functions to appropriate modules
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Semantic function clustering analysis identified 4 functions in wrong files - workflow compilation logic in git utilities, user interaction in git operations, config validation in workflow validation, and action validators in build commands.
Relocations
Workflow post-processing (
git.go→compile_post_processing.go):ensureGitAttributes()- manages.gitattributesfor compiled.lock.ymlfilesstageGitAttributesIfChanged()- stages gitattributes after compilationUser interaction (
git.go→interactive.go):confirmPushOperation()- prompts user for push confirmation usinghuhlibraryConfig validation (
compile_validation.go→compile_config.go):validateCompileConfig()- validates CLI flags (--dependabot,--purge,--dir)Action validation (
actions_build_command.go→validators.go):validateActionYml()- validates GitHub action metadata structureChanges
Logging updated to match new module contexts. Unused imports removed.
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Code Organization Recommendations</issue_title>
<issue_description>Semantic analysis of 490 Go source files in repository: githubnext/gh-aw
Executive Summary
A comprehensive semantic function clustering analysis has identified significant code organization patterns, outlier functions in wrong files, and duplicate implementations across the codebase. The analysis covered 490 non-test Go files across key packages, with deep focus on:
Key Findings:
Critical Issues Identified
1. Exact Duplicate Functions
Issue #1:
extractBaseRepo()- Identical Implementation in Two FilesDuplicate Locations:
pkg/workflow/action_resolver.go:93pkg/cli/update_actions.go:20Code Comparison:
Similarity: 100% identical logic, only comments differ
Recommendation:
pkg/repoutil/repoutil.go(which already has related utilities)ExtractBaseRepo(path string) stringrepoutil.ExtractBaseRepo()Estimated Impact: Reduced code duplication, single source of truth for repository path parsing
Issue #2:
ParseGitHubURL()- Similar Functions with Different ImplementationsDuplicate Locations:
pkg/repoutil/repoutil.go:28- Returns(owner, repo string, err error)pkg/parser/github_urls.go:56- Returns(*GitHubURLComponents, error)Implementations:
git@github.com:) and HTTPS formats, returns simple owner/repo tupleurl.Parse(), handles raw.githubusercontent.com, returns structuredGitHubURLComponentswith file paths, refs, etc.Analysis:
These functions have different purposes:
repoutil.ParseGitHubURL- Simple owner/repo extraction for git operationsparser.ParseGitHubURL- Comprehensive URL parsing with file paths, refs, and content typesRecommendation:
repoutil.ParseGitHubURL→repoutil.ParseGitRepoURL(emphasizes git repo focus)parser.ParseGitHubURLas-is (comprehensive parser)repoutilcallparserversion and extract owner/repo?Estimated Impact: Improved API clarity, reduced naming confusion
2. Outlier Functions (Functions in Wrong Files)
Priority 1: High-Impact Misplacements
Outlier #1: Git Attribute Configuration in Git Operations File
File:
pkg/cli/git.go:157Function:
ensureGitAttributes()Current Purpose: Configuring
.gitattributesfor compiled workflow filesIssue: This is compilation post-processing, not a core git operation
Used By:
compile_helpers.gocompile_orchestration.goadd_command.goWhy It's Misplaced:
The function sets up
.gitattributesto handle.mdand.ymlfiles in the.github/workflowsdirectory. This is a workflow compilation concern, not a generic git utility. The git.go file should contain reusable git operations (commits, branches, remotes), not workflow-specific configuration.Recommendation:
pkg/cli/compile_post_processing.go(or create it)configureWorkflowGitAttributes()for clarityEstimated Impact: Clearer separation of concerns, easier to find compilation-related setup
Outlier #2: User Interaction in Git Operations File
File:
pkg/cli/git.go:550Function:
confirmPushOperation()Issue: User interaction l...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.